package com.lambda.demo.stream;

import com.lambda.demo.models.AuthorsData;

import java.util.Arrays;

public class StreamFlatMapTest {
  public static void main(String[] args) {
    //要求打印出所有书籍的名字
    AuthorsData.getAuthors().stream()
      .flatMap(a -> a.getBooks().stream())
      .forEach(b -> System.out.println(b.getName()));

    System.out.println("=========要求获取所有的书籍分类===========");
    //要求获取所有的书籍分类
    AuthorsData.getAuthors().stream()
      .flatMap(a -> a.getBooks().stream())
      .flatMap(b -> Arrays.stream(b.getCategory().split(",")))
      .distinct()
      .forEach(System.out::println);
  }
}
